package cn.ulyn.seckill.util;

import javax.crypto.Cipher;
import javax.crypto.SecretKey;
import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.DESedeKeySpec;

public class DESede {
    private static final String Algorithm = "DESede";
    public static final String ISO88591 = "ISO-8859-1";

    public static byte[] decryptMode(byte[] keysBytes, byte[] paramArrayOfByte2) {
        byte[] arrayOfByte1;
        try {
            byte[] arrayOfByte2 = new byte[24];
            if (keysBytes.length >= 24) {
                System.arraycopy(keysBytes, 0, arrayOfByte2, 0, 24);
            } else {
                System.arraycopy(keysBytes, 0, arrayOfByte2, 0, keysBytes.length);
            }
            DESedeKeySpec localDESedeKeySpec = new DESedeKeySpec(arrayOfByte2);
            SecretKey localSecretKey = SecretKeyFactory.getInstance("DESede").generateSecret(localDESedeKeySpec);
            Cipher localCipher = Cipher.getInstance("DESede");
            localCipher.init(2, localSecretKey);
            arrayOfByte1 = localCipher.doFinal(paramArrayOfByte2);
        } catch (Exception localException) {
            localException.printStackTrace();
            arrayOfByte1 = null;
        }
        return arrayOfByte1;
    }

    public static byte[] encryptMode(byte[] paramArrayOfByte1, byte[] paramArrayOfByte2) {
        byte[] arrayOfByte1;
        try {
            byte[] arrayOfByte2 = new byte[24];
            if (paramArrayOfByte1.length >= 24) {
                System.arraycopy(paramArrayOfByte1, 0, arrayOfByte2, 0, 24);
            } else {
                System.arraycopy(paramArrayOfByte1, 0, arrayOfByte2, 0, paramArrayOfByte1.length);
            }
            DESedeKeySpec localDESedeKeySpec = new DESedeKeySpec(arrayOfByte2);
            SecretKey localSecretKey = SecretKeyFactory.getInstance("DESede").generateSecret(localDESedeKeySpec);
            Cipher localCipher = Cipher.getInstance("DESede");
            localCipher.init(1, localSecretKey);
            arrayOfByte1 = localCipher.doFinal(paramArrayOfByte2);

        } catch (Exception localException) {
            localException.printStackTrace();
            arrayOfByte1 = null;
        }
        return arrayOfByte1;
    }
}